<template>
	<view>
		<view class="top-tip">设置成功后，将通过服务号给您发送微信消息提醒</view>
		<view class="content">
			<view class="set-list flex align-center " v-for="(item,index) in list" :key="index">
				<view class="set-title">{{item.title}}</view>
				<view><switch disabled="true" @tap="switchClick(index)"  :checked="listKey[item.key] && listKey[item.key] == 1" style="zoom:.9" /></view>
			</view>
		</view>
		<view class="help" v-if="gzhData.a_url" @tap="locationUrl">查看如何关注公众号>></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				s_id:0,
				canSave:false,
				gzhData:{
					
				},
				listKey:{
					
				},
				list:[
					{title:'有人参加时通知我',key:'create_status'},
					{title:'有人修改时通知我',key:'edit_status'},
					{title:'有人取消时通知我',key:'delete_status'}
				]
			}
		},
		methods: {
			switchClick(index){
				var that = this;
				if(that.canSave == false)
				{
					if(that.gzhData.a_url)
					{
						that.showGzhTips();
					}else{
						that.$api.msg('初始化配置失败，请重新打卡该页面')
					}
					return ;
				}
				var listKey = that.listKey?JSON.parse(JSON.stringify(that.listKey)):{};
				var info = that.list[index];
				var value = (listKey[info.key] == 1)?-1:1;
				listKey[info.key] = value;
				this.setNoticeInfo(listKey);
			},
			setNoticeInfo(listKey)
			{
				var that = this;
				that.$api.loadingMsg('正在设置');
				that.$http.post('statistics/setNoticeInfo',{
					s_id:that.s_id,
					listKey
				}).then(res=>{
					that.$api.msg(res.msg);
					if(res.code == 1)
					{
						if(res.data.content)
						{
							that.listKey = res.data.content.statistics;
						}
					}
				})
			},
			setNoticeInit(){
				var that = this;
				that.$api.loadingMsg('正在获取配置');
				that.$http.post('statistics/setNoticeInit',{
					s_id:that.s_id
				}).then(res=>{
					if(res.code == 0)
					{
						that.$api.msg(res.msg)
					}else{
						var resData = res.data;
						var gzhData = resData.gzhData?resData.gzhData:{};
						that.gzhData = gzhData;
						that.canSave = (gzhData.status == 1)?false:true;
						if(gzhData.status == 1)
						{
							this.showGzhTips();
						}
						if(res.data.content)
						{
							that.listKey = res.data.content.statistics;
						}
					}
				})
			},
			showGzhTips(){
				var that = this;
				var gzhData = that.gzhData;
				that.$api.showModal(gzhData.tips,gzhData.content,function(e){
					if(e == 'yes')
					{
						that.$api.navigateTo(gzhData.a_url,2); 
					}
				},{
					confirmText:'去关注'
				})
			},
			locationUrl(){
				this.$api.navigateTo(this.gzhData.a_url,2); 
			}
		},
		onLoad(params) {
			//params.s_id = 10;
			if(params.s_id)
			{
				this.s_id = params.s_id;
			}
		},
		onShow() {
			if(this.s_id )
			{
				this.setNoticeInit();
			}
			
		}
	}
</script>

<style lang="scss">
.content{
	width: 100%;
	background: #FFFFFF;
	padding: 0 20rpx;
	.set-list{
		height: 120rpx;
		border-bottom: 2rpx solid #eeeeee;
		.set-title{
			width: 85%;
			font-size: 28rpx;
			color: #333333; 
		}
	}
}
.help{
	margin-top: 100rpx;
	font-size: 26rpx;
	text-align: center;
	color: $uni-btn-color;
}
.top-tip{
	height: 100rpx;
	line-height: 100rpx;
	padding: 0 20rpx;
	color: #999999;
	font-size: 28rpx;
}
</style>
